package com.zhentao.feign;

import com.zhentao.api.article.schedule.ISchedule;
import com.zhentao.model.dtos.ResponseResult;
import com.zhentao.model.schedule.dto.Task;
import com.zhentao.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class IScheduleImpl implements ISchedule {
    @Autowired
    private TaskService taskService;

    //添加延迟任务
    @PostMapping("/api/v1/task/add")
    public ResponseResult addTask(@RequestBody Task task){
         return ResponseResult.okResult(taskService.addTask(task));
    }

    //取消任务
    @GetMapping("/api/v1/task/{taskId}")
    public ResponseResult cancelTask(@PathVariable("taskId") Long taskId){
        return ResponseResult.okResult(taskService.cancelTask(taskId));
    }

    //按照类型和优先级 拉取任务
    @GetMapping("/api/v1/task/{type}/{priority}")
    public ResponseResult poll(@PathVariable("type") Integer type,
                               @PathVariable("priority") Integer priority){
        return ResponseResult.okResult(taskService.poll(type, priority));
    }

}
